C=======================================================================
C  TR_IPCROP, Subroutine
C
C  Read crop parameters from RICER970.SPE
C-----------------------------------------------------------------------
C  Revision history
C
C  06/15/1994 PWW Written
C  02/07/1993 PWW Header revision and minor changes
C  02/07/1993 PWW Added switch common block, restructured
C  08/29/2002 CHP/MUS Converted to modular format for inclusion in CSM.
C  08/12/2003 CHP Added I/O error checking
C=======================================================================

      SUBROUTINE TR_IPCROP (FILEC, PATHCR,  
     &    CO2X, CO2Y, MODELVER, PORMIN, 
     &    RWUEP1, RWUMX, P1, P1T,
     &    TBASE,P8,P9,PHINT,PCGRD,PCINT,
     &    KLITE,KROW,SROW,RUEA,LEAF1,LEAF3,
     &    LEAFT,KSHADE,HARVMAT,
     &    BF,TIPINT,TIPGRAD,TIPGRAD3,XTNMAX,
     &    PLAMAX,BMIN,BMIN2,BINT,BINT2,BGRAD,BGRAD2,
     &    SLA1,SLA2,SLA3,SLA4,SLA5,SLAT1,SLAT2, SLAT5,
     &    CARBR1,CARBR2,CARBR3,CARBR4,CARBL0,
     &    CARBL1,CARBL2,CARBL3,CARBL4,CARBC1,
     &    CARBC2,CARBC3,CARBC4,TCLRAT1,TCARBL2,TCARBL5,
     &    PETGR1,PETGR2,PETGR5,RGCORM,RGCORM2,
     &    RGCORMT,CMAT2,CMAT5,TCMAT,
     &    SUFAC1,SUFAC2,SUFAC3,SLGRD1,SLGRD2,
     &    SLINT,SLGRD5,SUCINT,SUCX1,SUCX2,SUCX3,
     &    RESPF,RSENCE,RPET,TCARBC1,TCARBC2,TCARBC3,
     &    RNINT,RCTFAC,TGRAD,RCONST,XNFINT,XNFGRAD,
     &    SLFWINT,SLFWGRD,SLFNINT,SLFNGRD,SLAIFC,
     &    SLFCGRD,SLFTINT,SLFTGRD,
     &    SEEDRV,MCORMWT,MPETWT,MLFWT,RLWR)

      IMPLICIT    NONE
      SAVE

      CHARACTER*1  BLANK
      CHARACTER*6  ERRKEY
      CHARACTER*12 FILEC
      CHARACTER*80 PATHCR
      CHARACTER*92 FILECC

      INTEGER       PATHL,LUNCRP,ERR

      PARAMETER (BLANK  = ' ')
      PARAMETER (ERRKEY = 'IPCROP')
   

      !CHARACTER*4 ACRO(9)
      !CHARACTER*6, PARAMETER :: ERRKEY = 'RI_IPC'
      !CHARACTER   BLANK*1,FILEC*12,PATHCR*80,CHAR*180,FILECC*92

      !INTEGER     I,J,PATHL,LUNCRP,ERR,LNUM
      INTEGER MODELVER
      INTEGER LEAF1,LEAF3,LEAFT

      REAL PORMIN, RWUEP1, RWUMX
      REAL, DIMENSION(10) :: CO2X, CO2Y, CO2X1, CO2Y1
      REAL TBASE,P8,P9,PHINT,PCGRD,PCINT
      REAL KLITE,KROW,SROW,RUEA
      REAL KSHADE,HARVMAT
      REAL BF,TIPINT,TIPGRAD,TIPGRAD3,XTNMAX
      REAL PLAMAX,BMIN,BMIN2,BINT,BINT2,BGRAD,BGRAD2
      REAL SLA1,SLA2,SLA3,SLA4,SLA5,SLAT1,SLAT2, SLAT5
      REAL CARBR1,CARBR2,CARBR3,CARBR4,CARBL0
      REAL CARBL1,CARBL2,CARBL3,CARBL4,CARBC1
      REAL CARBC2,CARBC3,CARBC4,TCLRAT1,TCARBL2,TCARBL5
      REAL PETGR1,PETGR2,PETGR5,RGCORM,RGCORM2
      REAL RGCORMT,CMAT2,CMAT5,TCMAT
      REAL SUFAC1,SUFAC2,SUFAC3,SLGRD1,SLGRD2
      REAL SLINT,SLGRD5,SUCINT,SUCX1,SUCX2,SUCX3
      REAL RESPF,RSENCE,RPET,TCARBC1,TCARBC2,TCARBC3
      REAL RNINT,RCTFAC,TGRAD,RCONST,XNFINT,XNFGRAD
      REAL SLFWINT,SLFWGRD,SLFNINT,SLFNGRD,SLAIFC
      REAL SLFCGRD,SLFTINT,SLFTGRD
      REAL SEEDRV,MCORMWT,MPETWT,MLFWT,RLWR
      REAL P1, P1T


      !
      ! Default CO2 response of AROID
      !
      DATA CO2X1 /   0, 220, 330, 440, 550, 660, 770, 880, 990,9999/
      DATA CO2Y1 /0.00,0.71,1.00,1.08,1.17,1.25,1.32,1.38,1.43,1.50/
      !
      ! Default values in the species file
      !
      MODELVER =    1
      !SHOCKFAC =  1.0
      RWUEP1   = 1.50 
      PORMIN   = 0.02             ! Minimum pore space
      RWUMX    = 0.02              ! Max root water uptake
      RLWR     = 1.05 !ROOTS
      CO2X     = CO2X1
      CO2Y     = CO2Y1
      LUNCRP = 10

      PATHL  = INDEX (PATHCR,BLANK)
      IF (PATHL .LE. 1) THEN
        FILECC = FILEC
      ELSE
        FILECC = PATHCR(1:(PATHL-1)) // FILEC
      ENDIF
      OPEN (LUNCRP,FILE = FILECC, STATUS = 'OLD',IOSTAT=ERR)
      IF (ERR .NE. 0) CALL ERROR(ERRKEY,ERR,FILEC,0)

C-----------------------------------------------------------------------
C     Read crop parameters from FILEC
C-----------------------------------------------------------------------

      READ (LUNCRP,100,ERR=20) TBASE,P8,P9,PHINT,PCGRD,PCINT

      READ (LUNCRP,101,ERR=20) KLITE,KROW,SROW,RUEA,LEAF1,LEAF3,
     &                         LEAFT,KSHADE,HARVMAT
      READ (LUNCRP,102,ERR=20) BF,TIPINT,TIPGRAD,TIPGRAD3,XTNMAX,
     &                         PLAMAX,BMIN,BMIN2,BINT,BINT2,BGRAD,BGRAD2
      READ (LUNCRP,103,ERR=20) SLA1,SLA2,SLA3,SLA4,SLA5,SLAT1,SLAT2,
     &                         SLAT5
      READ (LUNCRP,104,ERR=20) CARBR1,CARBR2,CARBR3,CARBR4,CARBL0,
     &                         CARBL1,CARBL2,CARBL3,CARBL4,CARBC1,
     &                         CARBC2,CARBC3,CARBC4,TCLRAT1,TCARBL2,
     &                         TCARBL5
      READ (LUNCRP,105,ERR=20) PETGR1,PETGR2,PETGR5,RGCORM,RGCORM2,
     &                         RGCORMT,CMAT2,CMAT5,TCMAT
      READ (LUNCRP,106,ERR=20) SUFAC1,SUFAC2,SUFAC3,SLGRD1,SLGRD2,
     &                         SLINT,SLGRD5,SUCINT,SUCX1,SUCX2,SUCX3
      READ (LUNCRP,107,ERR=20) RESPF,RSENCE,RPET,TCARBC1,TCARBC2,TCARBC3
      READ (LUNCRP,108,ERR=20) RNINT,RCTFAC,TGRAD,RCONST,XNFINT,XNFGRAD
      READ (LUNCRP,109,ERR=20) SLFWINT,SLFWGRD,SLFNINT,SLFNGRD,SLAIFC,
     &                         SLFCGRD,SLFTINT,SLFTGRD
      READ (LUNCRP,110,ERR=20) SEEDRV,MCORMWT,MPETWT,MLFWT,RLWR

      P1T = P1
      LEAFT = LEAFT*P1/1500.0  !FOR TARO ONLY

      CLOSE (LUNCRP)
      RETURN
      
   20 CALL ERROR (ERRKEY,1,' ',0)

C-----------------------------------------------------------------------
C     Format Strings
C-----------------------------------------------------------------------

  100 FORMAT (1X,3F7.1,3F7.2)
  101 FORMAT (4F7.3,3I3,F7.3,F5.2)
  102 FORMAT (5F7.3,F8.1,4F5.2,2F8.5)
  103 FORMAT (4F7.4,4F8.5)
  104 FORMAT (16F5.2)
  105 FORMAT (9F5.2)
  106 FORMAT (3F6.3,8F7.4)
  107 FORMAT (6F5.2)
  108 FORMAT (F8.4,F6.2,F8.4,3F6.2)
  109 FORMAT (5F5.2,F7.4,2F5.1)
  110 FORMAT (5F5.2)


      END SUBROUTINE TR_IPCROP


 